# coding=utf-8
import os
import allure
import pytest,jsonpath
from common.assert_operator import Pact,string_assert
from common.logger import Logger
from common.read_yaml import ReadYaml_By_Root_Dict, ReadYaml
from common.verification import Verification

string_assert = string_assert() # 字符串校验类
pact = Pact() # 契约校验类
verification = Verification()
data = ReadYaml().get_yaml_data(f'{os.path.abspath(__file__).split("_test.py")[0]}.yml')   # 读取数据

@allure.feature('归档')  # 测试报告显示测试功能
class Test_06_1_Archive():

    # 获取yml文件中[发起协商]的数据参数
    approve_process_params = data['归档']
    # 获取yml的title，并作为ids的值传给用例
    ids_list = jsonpath.jsonpath(approve_process_params,"$[*][0]")
    @pytest.mark.parametrize("title, param, expect", approve_process_params,ids=ids_list)
    def test_Archive(self, user_login, title, param, expect):
        # ************************用例参数解析************************
        allure.dynamic.description(f"{param['description']}")  # 动态解析用例描述在测试报告中展示
        USER,PROCESSNAME = param['user'],param['process_name']
        DBNodeVerify,DBExtendNodeVerify,MessageVerify = '主节点校验','扩展节点校验','消息校验'
        contract_format = pact.approve_pact_format()
        Logger.info("*************** {}开始执行用例 ***************".format(title))
        main = user_login.goto_Approve_Process(USER)    # 登录到审批类实例
        consult_response = main.approve_submit(param)    # 归档提交
        # 流程结束后校验
        verification.after_end(PROCESSNAME, consult_response,
                                   expect, contract_format, DBNodeVerify,MessageVerify,DBExtendNodeVerify)
        Logger.info("*************** {}结束执行用例 ***************".format(title))
